package model

import (
	"gorm.io/gorm"
	"smart-health-platforms/config"
	"time"
)

// 用户提现流水表
type DistributionWithdraw struct {
	Id        uint32    `gorm:"column:id;type:int UNSIGNED;comment:提现流水唯一id;primaryKey;not null;" json:"id"`  // 提现流水唯一id
	UserId    uint32    `gorm:"column:user_id;type:int UNSIGNED;comment:用户id;not null;" json:"user_id"`       // 用户id
	Available float64   `gorm:"column:available;type:decimal(10, 2);comment:提现金额;not null;" json:"available"` // 提现金额
	Withdraw  float64   `gorm:"column:withdraw;type:decimal(10, 2);comment:手续费;not null;" json:"withdraw"`    // 手续费
	Obtain    float64   `gorm:"column:obtain;type:decimal(10, 2);comment:获得金额;not null;" json:"obtain"`       // 获得金额
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);comment:提现时间;not null;" json:"created_at"`  // 提现时间
}

// 设置与数据库表的映射关系
func (dw *DistributionWithdraw) TableName() string {
	return "distribution_withdraw"
}

// 记录提现记录
func (dw *DistributionWithdraw) Create(tx *gorm.DB) error {
	return config.DB.Create(&dw).Error
}

// 提现流水列表
func (dw *DistributionWithdraw) List() (withdrawList []*DistributionWithdraw, err error) {
	err = config.DB.Where("user_id = ?", dw.UserId).Find(&withdrawList).Error
	return
}
